package com.music.music.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.music.common.log.annotation.Log;
import com.music.common.log.enums.BusinessType;
import com.music.common.security.annotation.RequiresPermissions;
import com.music.music.domain.MusicType;
import com.music.music.service.MusicTypeService;
import com.music.common.core.web.controller.BaseController;
import com.music.common.core.web.domain.AjaxResult;
import com.music.common.core.utils.poi.ExcelUtil;
import com.music.common.core.web.page.TableDataInfo;

/**
 * 音乐类型Controller
 * 
 * @author ruoyi
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/musictype")
public class MusicTypeController extends BaseController
{
    @Resource
    private MusicTypeService musicTypeService;

    /**
     * 查询音乐类型列表
     */
    @RequiresPermissions("music:musictype:list")
    @GetMapping("/list")
    public TableDataInfo list(MusicType musicType)
    {
        startPage();
        List<MusicType> list = musicTypeService.selectMusicTypeList(musicType);
        return getDataTable(list);
    }

    /**
     * 导出音乐类型列表
     */
    @RequiresPermissions("music:musictype:export")
    @Log(title = "音乐类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MusicType musicType)
    {
        List<MusicType> list = musicTypeService.selectMusicTypeList(musicType);
        ExcelUtil<MusicType> util = new ExcelUtil<MusicType>(MusicType.class);
        util.exportExcel(response, list, "音乐类型数据");
    }

    /**
     * 获取音乐类型详细信息
     */
    @RequiresPermissions("music:musictype:query")
    @GetMapping(value = "/{musicTypeId}")
    public AjaxResult getInfo(@PathVariable("musicTypeId") Integer musicTypeId)
    {
        return success(musicTypeService.selectMusicTypeByMusicTypeId(musicTypeId));
    }

    /**
     * 新增音乐类型
     */
    @RequiresPermissions("music:musictype:add")
    @Log(title = "音乐类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MusicType musicType)
    {
        return toAjax(musicTypeService.insertMusicType(musicType));
    }

    /**
     * 修改音乐类型
     */
    @RequiresPermissions("music:musictype:edit")
    @Log(title = "音乐类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MusicType musicType)
    {
        return toAjax(musicTypeService.updateMusicType(musicType));
    }

    /**
     * 删除音乐类型
     */
    @RequiresPermissions("music:musictype:remove")
    @Log(title = "音乐类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{musicTypeIds}")
    public AjaxResult remove(@PathVariable Integer[] musicTypeIds)
    {
        return toAjax(musicTypeService.deleteMusicTypeByMusicTypeIds(musicTypeIds));
    }
}
